package com.ruoyi.project.warehouse.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.project.warehouse.domain.RyInventoryCurrentStock;
import com.ruoyi.project.warehouse.domain.RyInventoryCurrentStockVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.warehouse.domain.WareCurrentStock;
import com.ruoyi.project.warehouse.service.IWareCurrentStockService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 当前库存Controller
 *
 * @author you
 * @date 2022-09-05
 */
@RestController
@RequestMapping("/warehouse/WareCurrentStock")
public class WareCurrentStockController extends BaseController
{
    @Autowired
    private IWareCurrentStockService wareCurrentStockService;

    /**
     * 查询当前库存列表
     */
//    @PreAuthorize("@ss.hasPermi('warehouse:WareCurrentStock:list')")
    @GetMapping("/list")
    public TableDataInfo list(WareCurrentStock wareCurrentStock)
    {
        startPage();
        List<WareCurrentStock> list = wareCurrentStockService.selectWareCurrentStockList(wareCurrentStock);
        return getDataTable(list);
    }

    /**
     * 查询总库当前库存列表
     */
//    @PreAuthorize("@ss.hasPermi('warehouse:WareCurrentStock:list')")
    @GetMapping("/mainList")
    public TableDataInfo mainList(WareCurrentStock wareCurrentStock)
    {
        startPage();
        wareCurrentStock.setDepotId(1L);//总库id
        List<WareCurrentStock> list = wareCurrentStockService.selectWareCurrentStockList(wareCurrentStock);
        return getDataTable(list);
    }

    /**
     * 查询工具库当前库存列表
     */
//    @PreAuthorize("@ss.hasPermi('warehouse:WareCurrentStock:list')")
    @GetMapping("/toolList")
    public TableDataInfo toolList(WareCurrentStock wareCurrentStock)
    {
        startPage();
        wareCurrentStock.setDepotId(2L);//工具库id
        List<WareCurrentStock> list = wareCurrentStockService.selectWareCurrentStockList(wareCurrentStock);
        return getDataTable(list);
    }

    /**
     * 根据仓库id查询当前仓库中的物品
     */
//    @PreAuthorize("@ss.hasPermi('warehouse:WareCurrentStock:list')")
    @GetMapping("/getInventoryByDepotId/{depotId}")
    public AjaxResult getInventoryByDepotId(@PathVariable("depotId") Long depotId){
        return AjaxResult.success(wareCurrentStockService.getInventoryByDepotId(depotId));
    }

    /**
     * 根据仓库id和物品id查询仓库中物品基本信息和当前库存
     */
//    @PreAuthorize("@ss.hasPermi('warehouse:WareCurrentStock:list')")
    @GetMapping("/getInfoByDepotInventoryId")
    public AjaxResult getInfoByDepotInventoryId(RyInventoryCurrentStock ryInventoryCurrentStock){
        return AjaxResult.success(wareCurrentStockService.getInfoByDepotInventoryId(ryInventoryCurrentStock));
    }



    /**
     * 导出当前库存列表
     */
//    @PreAuthorize("@ss.hasPermi('warehouse:WareCurrentStock:export')")
    @Log(title = "当前库存", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WareCurrentStock wareCurrentStock)
    {
        List<WareCurrentStock> list = wareCurrentStockService.selectWareCurrentStockList(wareCurrentStock);
        ExcelUtil<WareCurrentStock> util = new ExcelUtil<WareCurrentStock>(WareCurrentStock.class);
        util.exportExcel(response, list, "当前库存数据");
    }

    /**
     * 导出当前总仓库存列表
     */
//    @PreAuthorize("@ss.hasPermi('warehouse:WareCurrentStock:export')")
    @Log(title = "当前总仓库存列表", businessType = BusinessType.EXPORT)
    @PostMapping("/exportMain")
    public void exportMain(HttpServletResponse response, WareCurrentStock wareCurrentStock)
    {
        wareCurrentStock.setDepotId(1L);//总库id
        List<WareCurrentStock> list = wareCurrentStockService.selectWareCurrentStockList(wareCurrentStock);
        ExcelUtil<WareCurrentStock> util = new ExcelUtil<WareCurrentStock>(WareCurrentStock.class);
        util.exportExcel(response, list, "当前库存数据");
    }

    /**
     * 导出当前工具库存列表
     */
//    @PreAuthorize("@ss.hasPermi('warehouse:WareCurrentStock:export')")
    @Log(title = "前工具库存列表", businessType = BusinessType.EXPORT)
    @PostMapping("/exportTool")
    public void exportTool(HttpServletResponse response, WareCurrentStock wareCurrentStock)
    {
        wareCurrentStock.setDepotId(2L);//工具库id
        List<WareCurrentStock> list = wareCurrentStockService.selectWareCurrentStockList(wareCurrentStock);
        ExcelUtil<WareCurrentStock> util = new ExcelUtil<WareCurrentStock>(WareCurrentStock.class);
        util.exportExcel(response, list, "当前库存数据");
    }

    /**
     * 获取当前库存详细信息
     */
//    @PreAuthorize("@ss.hasPermi('warehouse:WareCurrentStock:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(wareCurrentStockService.selectWareCurrentStockById(id));
    }

    /**
     * 新增当前库存
     */
//    @PreAuthorize("@ss.hasPermi('warehouse:WareCurrentStock:add')")
    @Log(title = "当前库存", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WareCurrentStock wareCurrentStock)
    {
        return toAjax(wareCurrentStockService.insertWareCurrentStock(wareCurrentStock));
    }

    /**
     * 修改当前库存
     */
//    @PreAuthorize("@ss.hasPermi('warehouse:WareCurrentStock:edit')")
    @Log(title = "当前库存", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WareCurrentStock wareCurrentStock)
    {
        return toAjax(wareCurrentStockService.updateWareCurrentStock(wareCurrentStock));
    }

    /**
     * 删除当前库存
     */
//    @PreAuthorize("@ss.hasPermi('warehouse:WareCurrentStock:remove')")
    @Log(title = "当前库存", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wareCurrentStockService.deleteWareCurrentStockByIds(ids));
    }
}
